<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- styling.qdoc -->
  <title>Use Case - Style And Theme Support | Qt 5.12 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.12</a></td><td >Use Case - Style And Theme Support</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.12.3 参考指南</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#using-the-styling-qml-types">使用样式化QML类型</a></li>
<li class="level1"><a href="#accessing-the-system-palette">访问系统调色板</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">用例—样式和主题支持</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-usecase-styling.html-description -->
<div class="descr"> <a name="details"></a>
<p>使用qml进行样式设计涉及到创建一个可视类型并将其绑定到属性，或者直接为属性赋值。对于包含Qt Quick <a href="../qtquick/qtquick-modelviewsdata-modelview.html">delegates(委托)</a>的类型，可视类型附加到<i>delegate（委托）</i>属性。</p>
<p>当使用<a href="../qtquickcontrols1/qtquickcontrols1-index.html">Qt Quick 控件1</a>时，这些控件会从各自的<a href="supported-platforms.html">platforms（平台）</a>自动设置适当的样式。</p>
<a name="using-the-styling-qml-types"></a>
<h2 id="using-the-styling-qml-types">使用样式化QML类型</h2>
<p><a href="../qtquickcontrols1/qtquickcontrols1-index.html">控件</a> 都具有绑定到的<i>样式类型</i> 的<code>style</code> 属性。控件具有<a href="../qtquickcontrols1/qtquick-controls-styles-qmlmodule.html">Qt Quick 控件1样式</a>模块中对应的样式类型。例如， <a href="../qtquickcontrols1/qml-qtquick-controls-button.html">Button</a> 具有 <a href="../qtquickcontrols1/qml-qtquick-controls-styles-buttonstyle.html">ButtonStyle</a> 类型，<a href="../qtquickcontrols1/qml-qtquick-controls-menu.html">Menu</a> 具有 <a href="../qtquickcontrols1/qml-qtquick-controls-styles-menustyle.html">MenuStyle</a> 类型。样式类型提供了适用于其各自控件的属性，例如背景、标签，或者对于某些控件了来说，还有光标外观相应的样式。</p>
<pre class="qml">

  <span class="type"><a href="../qtquickcontrols/qml-qtquick-controls2-button.html">Button</a></span> {
      <span class="name">text</span>: <span class="name">qsTr</span>(<span class="string">&quot;Hello World&quot;</span>)
      <span class="name">style</span>: <span class="name">ButtonStyle</span> {
          <span class="name">background</span>: <span class="name">Rectangle</span> {
              <span class="name">implicitWidth</span>: <span class="number">100</span>
              <span class="name">implicitHeight</span>: <span class="number">25</span>
              <span class="name">border</span>.width: <span class="name">control</span>.<span class="name">activeFocus</span> ? <span class="number">2</span> : <span class="number">1</span>
              <span class="name">border</span>.color: <span class="string">&quot;#FFF&quot;</span>
              <span class="name">radius</span>: <span class="number">4</span>
              <span class="name">gradient</span>: <span class="name">Gradient</span> {
                  <span class="type"><a href="../qtquick/qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0</span> ; <span class="name">color</span>: <span class="name">control</span>.<span class="name">pressed</span> ? <span class="string">&quot;#ccc&quot;</span> : <span class="string">&quot;#fff&quot;</span> }
                  <span class="type"><a href="../qtquick/qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1</span> ; <span class="name">color</span>: <span class="name">control</span>.<span class="name">pressed</span> ? <span class="string">&quot;#000&quot;</span> : <span class="string">&quot;#fff&quot;</span> }
              }
          }
     }

</pre>
<p><b>注意:</b><a href="../qtquickcontrols1/qtquick-controls-styles-qmlmodule.html">Qt Quick 控件1样式</a> 是在Qt 5.1中引入的，需要<a href="../qtquick/qtquick-index.html">Qt Quick</a> 2.1&#x2e;</p><a name="accessing-the-system-palette"></a>
<h2 id="accessing-the-system-palette">访问系统调色板</h2>
<p><a href="../qtquick/qml-qtquick-systempalette.html">SystemPalette</a> 类型提供关于系统调色板信息的信息。QML应用程序可以使用此信息设置可视类型的外观，以匹配本机外观和感觉。此外，在<a href="supported-platforms.html#desktop-platforms">桌面</a>平台上，当改变状态时，例如当应用程序失去键盘焦点时，会使用不同的调色板。</p>
<p>在使用<a href="../qtquickcontrols1/qtquickcontrols1-index.html">控件</a>时， 已经使用了系统颜色。</p>
</div>
<!-- @@@qtquick-usecase-styling.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
